<template>
  <Modal
    ref="modal"
    title="线下支付-审核"
    width="600px"
  >
    <template #reference>
      <slot />
    </template>
    <el-form label-width="100px">
      <el-form-item
        label="汇款方户名"
        prop="offAccName"
      >
        <el-input
          :value="value.offAccName"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="开户行"
        prop="offBank"
      >
        <el-input
          :value="value.offBank"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="汇款账号"
        prop="offAccount"
      >
        <el-input
          :value="form.offAccount"
          disabled
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="text-center">
        <el-button
          type="danger"
          @click="handleReject"
        >
          审核拒绝
        </el-button>
        <el-button
          type="primary"
          @click="handleResolve"
        >
          审核通过
        </el-button>
      </div>
    </template>
  </Modal>
</template>

<script>
import { assign } from 'lodash-es'
import { payAudit } from '@/api/order'
import { isSuccess } from '@/utils/common'

export default {
    components: {
        Modal: () => import('@/components/Modal'),
    },
    props: {
        value: {
            type: Object,
            default() {
                return {}
            },
        },
    },
    data() {
        return {
            form: {},
        }
    },
    watch: {
        value: {
            immediate: true,
            handler(val) {
                if (val) {
                    this.form = assign({}, this.form, val)
                    this.form.payPrice = this.convertYuan2Fen(val.payPrice)
                }
            },
        },
    },
    methods: {
        async handleResolve() {
            const res = await payAudit({
                id: this.form.id,
                checkStat: 'pass',
            })
            if (isSuccess(res)) {
                this.$message.success('审核成功!')
                this.$store.dispatch('order/list')
                this.$refs.modal.hide()
            }
        },
        async handleReject() {
            const res = await payAudit({
                id: this.form.id,
                checkStat: 'reject',
            })
            if (isSuccess(res)) {
                this.$message.success('审核成功!')
                this.$store.dispatch('order/list')
                this.$refs.modal.hide()
            }
        },
    },
}
</script>